package com.phiture.erp.basic.web.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import com.phiture.erp.basic.core.service.*;
import com.phiture.erp.basic.web.vo.ErpBasicCommonVO;
import com.phiture.erp.common.enums.*;
import com.phiture.erp.stock.api.service.ErpWarehouseApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YH
 * @date 2025/4/2
 */

@Tag(name = "管理后台 - ERP BASIC 控制器")
@RestController
@RequestMapping("/erp/basic")
@RequiredArgsConstructor
public class ErpBasicController {
    private final ErpMaterialCategoryService materialCategoryService;
    private final ErpMaterialUnitService materialUnitService;
    private final ErpMaterialService materialService;
    private final ErpCustomerService customerService;
    private final ErpAccountService accountService;
    private final AdminUserApi adminUserApi;
    private final ErpWarehouseApi warehouseApi;
    private final ErpSupplierService supplierService;


    @GetMapping("/common")
    @Operation(summary = "获得基础数据公共配置")
    public CommonResult<ErpBasicCommonVO> getCommonConfig() {
        ErpBasicCommonVO vo = new ErpBasicCommonVO();
        // 物料信息
        vo.setMaterialMap(materialService.getMaterialMap());
        // 物料类别信息
        vo.setMaterialCategoryMap(materialCategoryService.getMaterialCategoryMap());
        // 物料单位信息
        vo.setMaterialUnitMap(materialUnitService.getMaterialUnitMap());
        // 物料采购状态
        vo.setMaterialPurchasingStatusMap(ErpMaterialPurchasingStatusEnum.MATERIAL_PURCHASING_STATUS_MAP);
        // 物料采购检验状态
        vo.setMaterialPurchasingCheckTypeMap(ErpMaterialPurchasingCheckTypeEnum.MATERIAL_PURCHASING_CHECK_TYPE_MAP);
        // 物料属性
        vo.setMaterialAttrMap(ErpMaterialAttrEnum.MATERIAL_ATTR_MAP);
        // 物料计划类型
        vo.setMaterialPlanModeMap(ErpMaterialPlanModeEnum.MATERIAL_PLAN_MODE_MAP);
        // 物料特性类型
        vo.setMaterialCharTypeMap(ErpMaterialCharTypeEnum.MATERIAL_CHAR_TYPR_MAP);
        // 物料计划策略
        vo.setMaterialPlanStrategyMap(ErpMaterialPlanStrategyEnum.MATERIAL_PLAN_STRATEGY_MAP);
        // 物料领料方式
        vo.setMaterialIssModeMap(ErpMaterialIssModeEnum.MATERIAL_ISS_MODE_MAP);
        // 客户信息
        vo.setCustomerMap(customerService.getCustomerMap());
        // 账户信息
        vo.setAccountMap(accountService.getAccountMap());
        // 用户信息
        vo.setUserMap(adminUserApi.getUserMap());
        // 仓库信息
        vo.setWarehouseMap(warehouseApi.getWarehouseMap());
        // 供应商信息
        vo.setSupplierMap(supplierService.getSupplierMap());
        // 物料基础信息
        vo.setMaterialInfoList(materialService.getMaterialListByStatus(ErpMaterialStatusEnum.OPEN.getStatus()));
        // 生产任务优先级
//        vo.setProductionTaskPriorityMap(ErpProductionTaskPriorityEnum.getMap());
        // 生产任务状态
        vo.setProductionTaskStatusMap(ErpProductionTaskStatusEnum.getMap());
        // 采购需求类型
        vo.setPurchaseDemandTypeMap(ErpPurchaseDemandTypeEnum.ERP_PURCHASE_DEMAND_TYPE_MAP);
        return CommonResult.success(vo);
    }
}
